import enum
from applications.extensions import db
from .base_model import BaseModel


class VersionType(enum.Enum):
    client = '客户端'
    server = '服务端'


class Version(BaseModel):
    __tablename__ = "version"
    __table_args__ = (db.UniqueConstraint("version", "type", "customer"), {
        'extend_existing': True,
        'mysql_charset': 'utf8mb4',
        'mysql_collate': 'utf8mb4_unicode_ci',
    })

    id = db.Column(db.Integer, primary_key=True)
    version = db.Column(db.String(16), nullable=False, comment='版本号')
    type = db.Column(db.Enum(VersionType), nullable=False, comment='客户端/服务端')
    path = db.Column(db.String(256), nullable=False, comment='文件路径')
    customer = db.Column(db.String(256), index=True, nullable=False, comment='客户名')
    useable = db.Column(db.Boolean, index=True, default=True, comment='是否可用')
    description = db.Column(db.String(256), default='', comment='描述')
    is_latest = db.Column(db.Boolean, index=True, default=False, comment='是否最新版')
